package com.easywan.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.easywan.dao.IRToolsName2BaseUsersDao;
import com.easywan.dao.IToolsNameDao;
import com.easywan.vo.BaseManagerUser;
import com.easywan.vo.RToolsName2BaseUsers;
import com.easywan.vo.ToolsName;

public class ToolsNameService implements IToolsNameService{
	@Autowired
	IToolsNameDao nameDao;
	@Autowired
	IRToolsName2BaseUsersDao rToolsName2BaseUsersDao;
	@Override
	public ToolsName getByName(String toolsName) {
		
		ToolsName toolsNameVo = new ToolsName();
		toolsNameVo.setName(toolsName);
		List<ToolsName> tools = nameDao.selectBy(toolsNameVo);
		if(tools != null && tools.size() > 0){
			return tools.get(0);
		}
		return null;
	}
	@Override
	public List<ToolsName> getUsersTools(Integer usersId) {
		
		return nameDao.selectUsersTools(usersId);
	}
	@Override
	public List<ToolsName> getAll() {
		return nameDao.selectByAll(new ToolsName());
	}
	@Override
	public RToolsName2BaseUsers getRToolsName(Integer userId, int i) {
		RToolsName2BaseUsers rtn2bu = new RToolsName2BaseUsers();
		rtn2bu.setToolsNameId(i);
		rtn2bu.setUid(userId);
		return rToolsName2BaseUsersDao.selectBy(rtn2bu ).get(0);
	}
	@Override
	public int click(ToolsName forTools) {
		ToolsName tools = new ToolsName();
		tools.setClickCounter((Integer.valueOf(forTools.getClickCounter()) + 1)+"");
		tools.setId(forTools.getId());
		return nameDao.upDateByPrimary(tools);
	}

}
